import { defineStore } from 'pinia'
import axios from 'axios'
import { NewsRes, NewsItem } from '../../types/data'
export default defineStore('newList', {
  state() {
    return {
      list: [] as NewsItem[]
    }
  },
  actions: {
    // 获取新闻列表
    async getNews(channelId: number) {
      const res = await axios.get<NewsRes>('http://geek.itheima.net/v1_0/articles?channel_id=' + channelId + '&timestamp=' + Date.now())
      // console.log(res.data.data.channels)
      this.list = res.data.data.results
    }
  }
})